home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
bc_ti
/
ti660.asc
< prev
next >
Wrap
Text File
|
1992-02-24
|
1KB
|
67 lines
PRODUCT : Borland C++ NUMBER : 660
VERSION : All
OS : PC DOS
DATE : February 25, 1992 PAGE : 1/1
TITLE : Dynamically Allocating >64K in Windows 3.0
In Windows the pointer returned by malloc() is really a selector.
When you malloc() more than 64k, Windows will set up multiple
selectors. To use the pointer you need to increment the offset
until it reaches 0x0000 again (it always starts at 0x0000). You
then need to add a constant value to the segment (Petzold says 8
for protected mode, 0x1000 for real mode. See page 295 of
Windows 3.0 Power Programming.), which will give the next
selector! For example:
/* Must be far... huge pointers do not work */
char far *pfoo;
/* 'pfoo' points to first 64k */
pfoo = (char far *) farmalloc (1000000ul);
/* Advance to next segment */
while (FP_OFF (pfoo) != 0x0000) pfoo++;
/* Now points to second 64K */
pfoo = MK_FP (FP_SEG (pfoo) + 8, 0x0000);